home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / surfmodl / surfm203.arc / SURFSRC.ARC / STORLINE.INC < prev    next >
Text File  |  1987-12-21  |  2KB  |  56 lines

  1. procedure STORLINE (X1, Y1, X2, Y2: integer; var Xpt, Ypt: points;
  2.     var Npts: integer);
  3.  
  4. { Store the line from (X1,Y1) to (X2,Y2) in an internal buffer array }
  5.  
  6. var X, Y: integer;                   { current point being stored }
  7.     Xfact: real;                     { factor for (X,Y) interpolation }
  8.     Ylow, Yhigh: integer;            { range of for loop }
  9.     First: boolean;                  { flag first dot of line }
  10.  
  11. begin
  12.   First := TRUE;
  13.   if (Y2 = Y1) then
  14.     Xfact := 0.0
  15.   else
  16.     Xfact := (X2-X1) / (Y2-Y1);
  17.   if (Y1 > Y2) then begin
  18.     Ylow := Y2;
  19.     Yhigh := Y1;
  20.   end else begin
  21.     Ylow := Y1;
  22.     Yhigh := Y2;
  23.   end;
  24.   if (Ylow < Gymin) then
  25.     Ylow := Gymin;
  26.   if (Yhigh > Gymax) then
  27.     Yhigh := Gymax;
  28.  
  29. { Store the line segment, making sure there is not more than one X
  30.   value for any given Y (unless Y1 = Y2, in which case only the two
  31.   endpoints should be saved).
  32. }
  33. { Make sure the entire line isn't out of bounds }
  34.   if (Ylow <= Gymax) and (Yhigh >= Gymin) then begin
  35.     for Y := Ylow to Yhigh do begin
  36.       if (Xfact = 0.0) then
  37.         if (First) then begin
  38.           X := X1;
  39.           First := FALSE;
  40.         end else
  41.           X := X2
  42.       else
  43.         X := X1 + round((Y-Y1) * Xfact);
  44.       Npts := Npts + 1;
  45.       if (Npts <= MAXPTS) then begin
  46.         Xpt[Npts] := X;
  47.         Ypt[Npts] := Y;
  48.       end;
  49.     end;  { for Y }
  50.   end; { if Ylow... }
  51.  
  52. { Flag error condition if array dimension exceeded }
  53.   if (Npts > MAXPTS) then
  54.     Npts := -1;
  55. end;  { procedure STORLINE }
  56.